<#if invalid?? && invalid>
<div class="alert alert-danger" role="alert">
	<strong>错误！</strong>
	无效的合同信息！
</div>
<#else>
<form class="contract-payout-form" action="${request.contextPath}/sub-contract/payout-plan" method="post">
	<input type="hidden" name="contract.id" value="${cid}" />
	<input type="hidden" name="createTime" value="${.now?string('yyyy-MM-dd')}" />
	<input type="hidden" name="payout" value="false" />
	<div class="row">
		<div class="col-md-12">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">
							<span class="not-null-star">*</span>
							付款单位
						</div>
					</div>
					<input type="text" class="form-control not-empty" name="moneyTo" value="${(data.type.collection)?string('',data.companyB)}" placeholder="最多100个汉字" />
				</div>
			</div>
		</div>
		<div class="col-md-12">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">
							<span class="not-null-star">*</span>
							付款事项
						</div>
					</div>
					<textarea rows="5" class="form-control not-empty" name="reason" placeholder="最多300个中文"></textarea>
				</div>
			</div>
		</div>
		<div class="col-md-12">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">
							<span class="not-null-star">*</span>
							付款负责人
						</div>
					</div>
					<input type="hidden" class="not-empty" name="header.id" value="${Session['login_user'].id}"/>
					<input type="text" class="form-control not-empty" value="${Session['login_user'].name}" readonly="readonly"/>
				</div>
			</div>
		</div>
		<div class="col-md-12">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">
							<span class="not-null-star">*</span>
							付款金额
						</div>
					</div>
					<input type="text" class="form-control not-empty number" name="total" placeholder="请输入付款金额">
					<div class="input-group-addon">元</div>
				</div>
			</div>
		</div>
		<div class="col-md-12">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">
							<span class="not-null-star">*</span>
							付款日期
						</div>
					</div>
					<input type="text" class="form-control not-empty datetimepicker" data-format="yyyy-MM-dd" data-foot="false" name="payoutTime" placeholder="请选择日期" readonly="readonly">
				</div>
			</div>
		</div>
		<div class="col-md-12">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">备注</div>
					</div>
					<textarea rows="5" class="form-control" name="remark" placeholder="最多1000个中文"></textarea>
				</div>
			</div>
		</div>
	</div>
	<hr>
	<div class="row">
		<div class="col-md-12 text-right">
			<div class="btn btn-primary btn-sm btn-submit">确定</div>
			&nbsp;
			<div class="btn btn-danger btn-sm btn-submit repeat">提交并继续</div>
			&nbsp;
			<div class="btn btn-default btn-sm" onclick="$.suredy.closeModal();">关闭</div>
		</div>
	</div>
</form>
<script type="text/javascript">
	$(function() {
		// 初始化日期控件
		$.suredy.datetimepicker.init();

		$('form.contract-payout-form .btn-submit').on('click', function() {
			var form = $('form.contract-payout-form');

			// 校验表单
			if (!$.suredy.formChecker(form)) {
				return false;
			}

			var $this = $(this);
			var okBtn = $('form.contract-payout-form .btn-submit');

			if (okBtn.hasClass('disabled'))
				return false;

			okBtn.addClass('disabled');

			form.ajaxSubmit({
				dataType : "json",
				success : function(data, textStatus, jqXHR) {
					if (!data || !data.success) {
						alert(data.msg || '记录付款计划信息失败!');
						okBtn.removeClass('disabled');
						return false;
					}

					$.suredy.refreshContent('${cid}', '${pid}', [ 'div#tab3' ]);

					if ($this.hasClass('repeat')) {
						alert('信息已记录！');
						form.get(0).reset();
						okBtn.removeClass('disabled');
						return;
					}

					$.suredy.closeModal();
				},
				error : function(jqXHR, textStatus, errorThrown) {
					alert('记录付款计划信息失败!\n' + errorThrown);
					okBtn.removeClass('disabled');
					return false;
				}
			});
		});
	});
</script>
</#if>
